<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
    <link rel="stylesheet" type="text/css" href="css/bootStrap.css?id=3">
    <link rel="stylesheet" href="css/mpicker.css?id=3">
    <title>成为合伙人</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .head {
            width: 100%;
            height: 250px;
        }

        .content {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .input {
            width: 100%;
            border-bottom: .5px solid #E5E5E5;
            height: 50px;
            display: flex;
            align-items: center;
            padding: 0 5%;
            color: #333333;
        }

        input {
            outline: none;
            border: 0;
            font-size: 15px;
            margin-left: 8px;
        }

        .bottom {
            margin: 30px 0;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
        }

        button {
            letter-spacing: 1px;
            color: #5D4421;
            background-image: linear-gradient(#F9E1BF, #EECA83);
            border: none;
            border-radius: 999px;
            width: 80%;
            height: 40px;
            line-height: 40px;
            outline: 0;
            display: block;
            margin: 0 auto;
        }

        .id_num {
            position: absolute;
            top: 180px;
            left: 30px;
            display: flex;
            align-items: center;
            color: #999999;
        }

        .agreement {
            color: #EECA83;
        }
    </style>
</head>

<body>
    <div class="contain">
        <img class="head" src="./image/card.png" alt="">
        <div class="id_num">
            <div style="margin-right: 10px;">ID:</div>
            <span id="id_number"></span>
        </div>
        <div class="content">
            <div class="input">
                <span>姓名:</span><input type="span" id="name" placeholder="请输入您的姓名" />
            </div>
            <div class="input">
                <span>电话:</span><input type="span" id="tel" placeholder="请输入您的电话" />
            </div>
            <div class="input">
                <span>城市:</span><input type="span" id="area" value="陕西省-西安市" />
            </div>
            <div class="input">
                <span>开户行:</span><input type="span" id="bank" placeholder="请输入您的开户行" readonly="true" />
            </div>
            <div class="input">
                <span>银行卡号:</span><input type="number" id="number" placeholder="请输入您的银行卡号" />
            </div>
        </div>
        <div class="bottom">
            <span style="color:#333333;">点击阅读并同意</span>
            <div class="agreement">《分销合伙人协议》</div>
            <input type="radio" name="rd" value="4" class="choose"></input>
        </div>
        <button class="confirms">确定加入</button>
    </div>
    <div class="picker">
        <div class="picker-mask"></div>
        <div class="picker-main picker-bottom">
            <div class="picker-header">银行选择</div>
            <div class="picker-content" style="height: 216px;">
                <div class="picker-list" style="width: 50%; height: 216px;">
                    <ul id="ul_first">
                    </ul>
                </div>
                <div class="picker-list" style="width: 50%; height: 216px;">
                    <ul id="ul_second">
                    </ul>
                </div>
            </div>
            <div class="picker-footer">
                <div class="yes">确定</div>
                <div class="no">取消</div>
            </div>
        </div>
    </div>
</body>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/json.js"></script>
<script src="js/jsonExchange.js"></script>
<script src="js/mPicker.min.js"></script>
<script>
    $(() => {
        let id = getUrldata('Uid')
        let key = getUrldata('key')
        let reg = /([^\u0020-\u007E\u00A0-\u00BE\u2E80-\uA4CF\uF900-\uFAFF\uFE30-\uFE4F\uFF00-\uFFEF\u0080-\u009F\u2000-\u201f\u2026\u2022\u20ac\r\n])|(\s)/g
        $('.picker').hide()
        let u = navigator.userAgent;
        // 判断ios
        let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
        // 判断android
        let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1

        //判断微信
        function isWeiXin() {
            var ua = window.navigator.userAgent.toLowerCase();
            if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                return true; // 是微信端
            } else {
                return false;
            }
        }

        // 进入用户协议
        $('.agreement').click(() => {
            window.location.href = 'aggrement.html'
        })

        function getUrldata(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return decodeURI(r[2]);
            return null;
        }

        // 统一弹框
        function info_alert(param) {
            if (isWeiXin()) {
                (() => {
                    window.alert = function (name) {
                        var iframe = document.createElement("IFRAME");
                        iframe.style.display = "none";
                        iframe.setAttribute("src", 'data:text/plain');
                        document.documentElement.appendChild(iframe);
                        window.frames[0].window.alert(name);
                        iframe.parentNode.removeChild(iframe);
                    }
                })()
                alert(param)
                return
            }
            if (isiOS) {
                window.webkit.messageHandlers.showAlert.postMessage(param)
                return
            }
            if (isAndroid) {
                window.TiantianCharge_Android.showAlert(param)
                return
            }
        }

        $('#area').mPicker({
            level: 2,
            dataJson: dataJson,
            Linkage: true,
            rows: 6,
            idDefault: true,
            splitStr: '-',
            header: '<div class="mPicker-header">省市选择</div>',
            confirm: function (json) {
                console.info(json)
                $('#area').val(json.name)
            },
            cancel: function (json) {
            }
        })

        // 取消
        $('.no').click(() => {
            $('.picker').hide()
        })

        // 获取用户id
        $.ajax({
            url: 'https://api.cd1a.cn/index.php/activity/Trans/ispartner',
            data: {
                userid_locked: id
            },
            type: 'POST',
            dataType: 'json',
            success: function (res) {
                console.log(res)
                $('#id_number').html(res.data)
            }
        })

        // 开户行选择
        $('#bank').click(() => {
            $('.picker').show()
            $('#ul_first').empty()
            $('#ul_second').empty()
            let area = $('#area').val()
            let zone = area.split('-')[1].replace('市', '')
            $.ajax({
                url: 'https://api.cd1a.cn/index.php/activity/Trans/banklist',
                data: {
                    city: zone
                },
                type: 'POST',
                dataType: 'json',
                success: function (res) {
                    console.log(res)
                    if (res.code == 1) {
                        for (let i = 0; i < res.data.length; i++) {
                            let one = `<li class=${i} id="first">` + res.data[i].belong_bank + '</li>' // 银行归属地
                            $('#ul_first').append(one)
                        }
                        // 选择银行
                        $('#ul_first').click(e => {
                            $('#ul_second').animate({
                                scrollTop: 0
                            })
                            for (let i = 0; i < res.data.length; i++) {
                                $(`.${i}`).css('background', 'rgb(245,245,245)')
                                if (e.target.innerHTML == res.data[i].belong_bank) {
                                    $(`.${i}`).css('background', '#A5A4A4')
                                    $('#ul_second').empty()
                                    for (let a = 0; a < res.data[i].back_list.length; a++) {
                                        let two = `<li class=${a + 'c'} id="second">` + res.data[i].back_list[a].branch_familiar_style + '</li>' // 银行支行
                                        $('#ul_second').append(two)
                                    }
                                    // 选择银行归属地
                                    $('#ul_second').click(e => {
                                        for (let a = 0; a < res.data[i].back_list.length; a++) {
                                            $(`.${a + 'c'}`).css('background', 'rgb(245,245,245)')
                                            if (e.target.innerHTML == res.data[i].back_list[a].branch_familiar_style) {
                                                $(`.${a + 'c'}`).css('background', '#A5A4A4')
                                                $('.yes').click(() => {
                                                    $('.picker').hide()
                                                    $('.yes').data('res', res.data[i].back_list[a].branch_code)
                                                })
                                            }
                                        }
                                    })
                                    $('.yes').click(() => {
                                        $('.picker').hide()
                                        $('#bank').val(res.data[i].belong_bank)
                                    })
                                }
                            }
                        })
                    } else {
                        info_alert(res.msg)
                    }
                }
            })
        })

        $('.confirms').click(() => {
            let name = $('#name').val()
            let tel = $('#tel').val()
            let bank = $('#bank').val()
            let number = $('#number').val()
            let radio_type = $('input:radio:checked').val()
            let code = $('.yes').data('res')
            if (name == '' || tel == '' || bank == '' || number == '') {
                info_alert('请输入内容')
            } else if (/^1[3456789]\d{9}$/.test(tel) == false) {
                info_alert('输入电话有误')
            } else if (reg.test(name) || reg.test(tel) || reg.test(bank) || reg.test(number)) {
                info_alert('不支持此类型内容')
            } else if (radio_type == undefined) {
                info_alert('请选择协议')
            } else {
                $.ajax({
                    url: 'https://api.cd1a.cn/index.php/activity/Trans/partner',
                    type: 'POST',
                    data: {
                        userid_locked: id,
                        name: name,
                        tel: tel,
                        deposit: code,
                        back_code: number
                    },
                    dataType: 'json'
                }).then(res => {
                    console.log(res)
                    if (res.code == 1) {
                        if (isWeiXin()) {
                            (() => {
                                window.alert = function (name) {
                                    var iframe = document.createElement("IFRAME");
                                    iframe.style.display = "none";
                                    iframe.setAttribute("src", 'data:text/plain');
                                    document.documentElement.appendChild(iframe);
                                    window.frames[0].window.alert(name);
                                    iframe.parentNode.removeChild(iframe);
                                }
                            })()
                            alert('录入成功')
                            // 从分销商城进来的用户
                            if (window.__wxjs_environment === 'miniprogram') {
                                if (key != 'undefined' && key != 'null') {
                                    wx.miniProgram.reLaunch({
                                        url: '/pages/product/product?id=' + key
                                    })
                                } else {
                                    window.location.href = 'javascript:history.go(-1)'
                                }
                            }
                        }
                        if (isiOS) {
                            if (key == '1') {
                                window.webkit.messageHandlers.goBack.postMessage('录入成功')
                            } else {
                                window.webkit.messageHandlers.showAlert.postMessage('录入成功')
                                window.location.href = 'javascript:history.go(-1)'
                            }
                        }
                        if (isAndroid) {
                            if (key == '1') {
                                window.TiantianCharge_Android.showAlert('录入成功')
                                window.TiantianCharge_Android.closeH5()
                            } else {
                                window.TiantianCharge_Android.showAlert('录入成功')
                                window.location.href = 'javascript:history.go(-1)'
                            }
                        }
                    } else {
                        info_alert(res.msg)
                    }
                })
            }
        })
    })
</script>

</html>